# -*- coding: utf-8 -*-

'''eof
name:申请企业是否为教辅行业
code:R76_EntTeachingAuxiliaryIndustryCheck_GZ
tableName:
columnName:
groups:企业通用模块
dependencies:TX_GZ_DSJ,EG_DSJ
type:常用指标
datasourceType:在线指标
description:
eof'''


import sys
import pandas as pd
import json
from datetime import datetime


def FormatData_SF(tableName):
    try:
        eg = EG_DSJ.get("data").get("R1103V3")[0].get(tableName)
        return eg if isinstance(eg, list) else [{}]
    except:
        return [{}]

def FormatData_SW(tableName):
    try:
        eg = TX_GZ_DSJ.get('data').get(tableName)
        return eg if isinstance(eg, list) else [{}]
    except:
        return [{}]


def R76_EntTeachingAuxiliaryIndustryCheck_GZ():
    null_type_list = ['', ' ', None, 'null', 'Null', 'NULL', '/', '-', '--']
    try:
        TX = FormatData_SW('syptGsdjxx')
        SF = FormatData_SF('basicList')
        if TX == [{}] and SF == [{}]:
            return u'缺失值'
        else:
            hydm_1 = TX[0].get('HY_DM', '')
            hydm_2 = SF[0].get('industryCode', '')
            if hydm_1 in null_type_list and hydm_2 not in null_type_list:
                if hydm_2 in ['8394', '8399']:
                    return 0
                else:
                    return 1
            elif hydm_1 in null_type_list and hydm_2 in null_type_list:
                return u'缺失值'
            else:
                if hydm_1 in ['8394', '8399']:
                    return 0
                else:
                    return 1
    except:
        return u'缺失值'


if __name__ == "__main__":
    with open(r'C:\Users\zdr\Desktop\samples\EG_DSJ.json') as ff:
        EG_DSJ = json.loads(ff.read())
    with open(r'C:\Users\zdr\Desktop\samples\TX_GZ_DSJ.json') as ff:
        TX_GZ_DSJ = json.loads(ff.read())['parsedContent']
    aa = R76_EntTeachingAuxiliaryIndustryCheck_GZ()
    print aa
result = R76_EntTeachingAuxiliaryIndustryCheck_GZ()

